<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
</head>
<body>
<div id="app">
    <h2>{{info.name}}</h2>
    <button v-on:click="changeInfo">修改info</button>
</div>
<script src="https://unpkg.com/vue@3"></script>
<script>
    const app=Vue.createApp({
        data(){
            return{
                info:{name:'why',age:19}
            }
        },
        watch:{
            // info:{
            //     handler(newVal,oldVal){
            //         console.log("侦听到info改变：",newVal,oldVal)
            //     },
            //     deep:true,
            //     immediate:true
            // },
            "info.name": {
                handler(newVal,oldVal){
                    console.log("info.name：",newVal,oldVal)
                },
                deep:true,
                immediate:true
            }
        },
        methods:{
            changeInfo(){
                this.info.name="idng"
            }
        }
    })
    app.mount("#app")
</script>
</body>
</html>